// 上面这个代码处理过度动画（默认加上不用管）
document.addEventListener('DOMContentLoaded', () => {
  setTimeout(() => {
    document.body.classList.add('sidenav-pinned')
    document.body.classList.add('ready')
  }, 200)
})

// 每个页面都会导入该js 统一的设置写这里即可
const toast = new bootstrap.Toast(document.querySelector('#myToast'), {
  delay: 1000,
});

axios.defaults.baseURL = 'http://ajax-api.itheima.net';
//弹框
function toasts(mag) {
  document.querySelector('#myToast .toast-body').innerHTML = mag;
  toast.show();
}
//请求拦截
  axios.interceptors.request.use( config=>{
  config.headers.Authorization=localStorage.getItem('teoken')    
  return config
  
}),(err)=>{
console.log('请求失误')
  return Promise.reject(err)
}

//响应拦截
axios.interceptors.response.use(
 (res)=>{     
 console.log('响应成功',res.status)
 console.log('响应成功')
 return res
 },(err)=>{

  if(err.response.status===401){
    localStorage.removeItem('teoken')
    location.assign('file:///D:/ajax%E5%AD%A6%E4%B9%A0/project-static-%E9%9D%99%E6%80%81%E6%A8%A1%E6%9D%BF/login.html')
   }
  return Promise.reject(err)
}

 
 )


 const resdfa=  document.querySelector('.font-weight-bold')
 resdfa&&(resdfa.innerHTML=localStorage.getItem('name'))
//退出

  const tuichu= document.querySelector('#logout')
  tuichu&&(tuichu.onclick=function(){
   localStorage.removeItem('teoken')
  location.assign('file:///D:/ajax%E5%AD%A6%E4%B9%A0/project-static-%E9%9D%99%E6%80%81%E6%A8%A1%E6%9D%BF/login.html')
 
  })
